﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Code4WP7SDK
{
    public class WeakAction<T> : WeakAction, IExecuteWithObject
    {
        private readonly Action<T> _action;

        public WeakAction(object target,Action<T> action) : base(target,null)
        {
            _action = action;
        }

        public Action<T> Action
        {
            get
            {
                return _action;
            }
        }

        public new void Execute()
        {
            if (_action != null && IsAlive)
            {
                _action(default(T));
            }
        }

        public void Execute(T parameter)
        {
            if (_action != null && IsAlive)
            {
                _action(parameter);
            }
        }

        public void ExecuteWithObject(object parameter)
        {
            var castParameter = (T)parameter;
            Execute(castParameter);
        }
    }
}
